<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加账户</title>
<link rel="stylesheet" type="text/css" href="admin/css/style.css" />
<link rel="stylesheet" type="text/css" media="all" href="admin/css/niceforms-default.css" />
<link rel="stylesheet" type="text/css" media="all" href="admin/js/date/jquery-ui-1.8.16.custom.css" />
<script type="text/javascript" src="admin/js/jquery.min.js"></script>
<script type="text/javascript" src="admin/js/niceforms.js"></script>
<script type="text/javascript" src="admin/js/ddaccordion.js"></script>
<script type="text/javascript" src="admin/js/jconfirmaction.jquery.js"></script>
<script type="text/javascript" src="admin/js/jquery.jclock-1.2.0.js"></script>
<script type="text/javascript" src="admin/js/date/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="admin/js/date/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript">
ddaccordion.init({
	headerclass: "submenuheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [4], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["suffix", "<img src='<%=basePath%>admin/images/plus.gif' class='statusicon' />", "<img src='<%=basePath%>admin/images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
});
</script>
<script type="text/javascript">
	$(document).ready(function() {
	    $('.jclock').jclock();
	
		$("#operTime1").datepicker( {
			changeMonth : true,
			changeYear : true,
			dateFormat : 'yy-mm-dd'
		});
		$("#operTime2").datepicker( {
			changeMonth : true,
			changeYear : true,
			dateFormat : 'yy-mm-dd'
		});
		$("#ui-datepicker-div").css('font-size', '0.8em') //改变大小
	
		//$( "#dialog:ui-dialog" ).dialog( "destroy" );
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 500,
			width: 655,
			modal: true,
			buttons: {
				"选择": function() {
					var cId = $("#tbody input:radio[checked]").val();
					var customer = $("#tbody input:radio[checked]").parent().next().html();
					$("#customer").val(customer);
					$("#customerId").val(cId);					
 					$( this ).dialog( "close" );
				},
				"取消": function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
			}
		});
		
		$( "#dialog-card" ).dialog({
			autoOpen: false,
			height: 750,
			width: 680,
			modal: true,
			buttons: {
				"选择": function() {
					var cId = $("#inventory input:radio[checked]").val();
					$("#cardNo").val(cId);
 					$( this ).dialog( "close" );
				},
				"取消": function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
			}
		});
		
	});
	
	function chooseCustomer(){
		$("#dialog-form").dialog("open");
	}
	
	function chooseCard(){
		$.post('issuerAction!getAllIssuersAjax',
			function(data){

				eval("var d ="+data);
				eval("var dd ="+d.result);
				var str = "<option value='-1'>--请选择--</option>";
				for(var i=0; i<dd.length; i++){
					str += "<option value='"+dd[i].cardIssuerId+"'>"+dd[i].name+"</option>";				
				}
				$("#cardIssuers").html(str);
			}
		);
		
		$("#dialog-card").dialog("open");
	}
	
	function queryCard(){
		
		if($("#faceValue").val().trim()=="");
		$("#faceValue").attr('disabled','disabled');
		
		$.post('inventory!queryInventoryAjax',$("#cardForm").serialize(),
					 function(data) {
						eval("var d="+data);
						eval("var d1="+d.result);
						eval("var d2="+d.result2);
						$("#totalSize").html(d2.totalSize);
						$("#cpg").html(d2.currentPage);
						$("#totalPage").html(d2.totalPage);
						$("#faceValue").attr('disabled','');
						
						var str = "";
						for(var i=0; i<d1.length; i++){
							str += "<tr><td><input type='radio' name='userId' value='"+d1[i].inventoryNo+"'></td>";
							str += "<td>"+d1[i].inventoryNo+"</td><td>"+d1[i].faceValue+"</td><td>"+d1[i].batchNo+"</td></tr>"
						}
						$("#inventory").html(str);
  					 }
  		);
  		
  		$("#tfood").attr("style", "");
	}
	
	function queryCustomer(){
		$.post('customerAction!queryCustomerAjaxAction',$("#userForm").serialize(),
					 function(data) {
						eval("var d="+data);
						eval("var dd="+d.result);
						var str = "";
						for(var i=0; i<dd.length; i++){
								str+="<tr><td><input type='radio' name='customerId' value='"+dd[i].customerId+"'></input></td><td colspan='2'>"+dd[i].name+"</td><td aligh='center' colspan='2'>"+dd[i].certificateNo+"</td></tr>";
						}
						$("#tbody").html(str);
  					 }
  		);
	}
	
	
	function firstPage() {
		$('#currentPage').attr('value',  1);
		queryCard();
	}
	
	function lastPage() {
		var currentPage = $("#totalPage").html();
		$('#currentPage').attr('value',  parseInt(currentPage));
		queryCard();
	}
	
	function backPage() {
		var currentPage = $("#cpg").html();
		$('#currentPage').attr('value',  parseInt(currentPage)-1);
		queryCard();
	}
		
	function nextPage() {
		var currentPage = $("#cpg").html();
		$('#currentPage').attr('value', parseInt(currentPage)+1);
		queryCard();
	}
	
	function goPage() {
		var goPage = Number($('#goPage').attr('value'));
		if(isNaN(goPage)) {
			$('#goPage').attr('value', '');
			return;
		}
		$('#currentPage').attr('value', goPage);
		queryCard();
	}
	
	function addAccount() {
		
		var str = "";
	
		var score = $("#score").val();
		var m=/\d+/;
		if(!m.test(score))
	    {
		 	str = "请填写正确的积分";
	 	}
	
		var balanceWarn = $("#balanceWarn").val();
		if(cardType=="-1"){
			str = "请选择余额提醒";
		}
	
		var cardType = $("#cardType").val();
		if(cardType=="-1"){
			str = "请选择卡类型";
		}
		
		var creditAmount = $("#creditAmount").val();
		if(!m.test(creditAmount)){
			str = "请填写正确的额度";
		}
		
		var cardNo = $("#cardNo").val();
		if (cardNo == "") {
			str = "请选择卡号";
		}
		
		var customer = $("#customer").val();
		if (customer == "") {
			str = "请选择用户";
		}
			
		var singleExpense = $("#singleExpense").val();
		if (!m.test(singleExpense)) {
			str = "请填写单次消费限额";
		}
		
		var name = $("#name").val();
		if (name.trim() == "") {
			str = "请填写 名称";
		}
		
		if(str!=""){
			$("#error").html(str);
		}else{
			$("#addForm").submit();
		}
	}
	
</script>
</head>

<body>
<div id="main_container">
       <%@include file="../header.jsp"%>
    <div class="main_content">
       <%@include file="menu.jsp"%>
   		 <div class="center_content">  
  		  <div class="left_content">
  				   <%@include file="sidebarmenu_sys.jsp"%>
    	  </div>  
    	
		    <div class="right_content">            
		        
		    	<h5>当前位置: 卡系统 &gt; 账户信息管理&gt; 添加账户</h5>  
		      
		      	<!-- dialog -->
		      	<div id="dialog-form" title="选择用户">
			      	<form action="#" id="userForm"
								name="queryForm" method="post">
						<table id="rounded-corner">
							<tbody>
										<tr>
											<td colspan="4"></td>
										</tr>
										<tr>
											<td align="right">
												姓 名：
											</td>
											<td align="left">
												<input type="text" name="customer.name" id="name" size="24" />
											</td>
											<td>
												<a href="javascript:queryCustomer();"
													class="bt_blue"> <span class="bt_blue_lft"></span><strong>查找</strong><span
													class="bt_blue_r"></span> </a>
											</td>
											<td></td>
										</tr>
							</tbody>
						</table>
					</form>
						<table id="rounded-corner">
							<thead>
								<tr>
									<th scope="col" width="5%" class="rounded-company">选择</th>
									<th scope="col" class="rounded" colspan="2">
										姓名
									</th>
									<th scope="col" class="rounded-q4" colspan="2">
										证件号码
									</th>
								</tr>
							</thead>
							<tbody id="tbody">
							</tbody>
						</table>	
				</div>
		      	<!-- dialog -->
				
				<!-- dialog for card -->
				<div id="dialog-card" title="选择卡">
					<form action="inventory!queryInventory" id="cardForm" name="cardForm" method="post">
		        		<input type="hidden" name="currentPage" id="currentPage" value="1" />
						<table id="rounded-corner" summary="2007 Major IT Companies' Profit">
						    <thead>
						    	<tr>
						        	<th scope="col" class="rounded-company" width="20%"></th>
						            <th scope="col" class="rounded" width="30%" align="right">查询库存卡</th>
						            <th scope="col" class="rounded" width="20%"></th>
						            <th scope="col" class="rounded-q4" width="30%"></th>
						        </tr>
						    </thead>
						    <tbody>
						    	<tr>
						            <td align="right">发卡商：</td>
						            <td align="left">	
						            	<select id="cardIssuers" name="inventory.cardIssuer.cardIssuerId"></select>
						           </td>
						           <td align="right">卡类型：</td>
						            <td align="left">
						            	<s:select list="#application.dics.DIC_CARD_MATERIAL_TYPE" listKey="value" listValue="name" value="%{inventory.materialType}" headerKey="-1" headerValue=" -- 请选择 -- " 
						            		name="inventory.materialType" id="materialType" theme="simple" cssStyle="font-size:12px;"></s:select>
						            </td>
						        </tr>   
						        <tr>
						            <td align="right">卡状态：</td>
						            <td align="left">
							            <!--<s:select list="#application.dics.DIC_CARD_BATCH_STATUS" listKey="value" listValue="name" value="%{inventory.status}" headerKey="-1" headerValue=" -- 请选择 -- " 
							            		name="inventory.status" id="status" theme="simple" cssStyle="font-size:11px;"></s:select>
										--><input type="text" value="已制卡" disabled="disabled"/>						            	
						            </td>
						            <td align="right">批次号：</td>
						            <td align="left"><input type="text" name="inventory.batchNo" id="batchNo"  size="18" maxlength="10" title="请输入批次号" /></td>
						        </tr> 
						        <tr>
						        	<td align="right"> 卡 号 ：</td>
						            <td align="left"><input type="text" name="inventory.inventoryNo" id="inventoryNo"  size="18" maxlength="10" title="请输入卡号" /></td>
						            <td align="right"> 面 值 ：</td>
						            <td align="left"><input type="text" name="inventory.faceValue" id="faceValue" size="18" title="精确到小数点后两位，如0.00" /> (￥)</td>
						        </tr> 
						        <tr>
						            <td align="right">创建时间：</td>
						            <td align="left" colspan="2">
						            	From <input type="text" name="operTime1" id="operTime1"  size="12" maxlength="12" />
						            	 To  <input type="text" name="operTime2" id="operTime2"  size="12" maxlength="12" />
						            </td>
						            <td align="left">
						            	<a href="javascript:queryCard();" class="bt_blue">
				         					<span class="bt_blue_lft"></span><strong>查询</strong><span class="bt_blue_r"></span>
				        				</a>
						            </td>
						        </tr> 
						    </tbody>
						</table>
					</form>
					<table id="rounded-corner" summary="2007 Major IT Companies' Profit">
					    <thead>
					    	<tr>
					            <th scope="col" class="rounded-company" width="10%">选择</th>
					            <th scope="col" class="rounded" width="35%">卡号</th>
					            <th scope="col" class="rounded" width="20%">面值(￥)</th>
					            <th scope="col" class="rounded-q4" width="35%">批次号</th>
					        </tr>
					    </thead>
				        <tfoot id="tfood" style="display:none;">
				    		<tr>
					        	<td class="rounded-foot-left" colspan="2">
					        	<div class="pager">
						     		共<span id="totalSize"></span>条记录，
						     		当前第<span id="cpg"></span> / <span id="totalPage"></span>页
			     				</div>
					        	</td>
					        	
					        	<td colspan="2">
					        		<div class="goPage">
										<a href="javascript:firstPage();">|&lt;&lt; first</a>
										<a href="javascript:backPage();"><span>&lt;&lt; prev</span></a>
										<a href="javascript:void(0)"><input type="text" name="goPage" id="goPage" value="" size="2" maxlength="4" onblur="goPage();" /></a>
										<a href="javascript:nextPage();">next &gt;&gt;</a>
										<a href="javascript:lastPage();">last &gt;&gt;|</a>
							        </div>
					        	</td>
					        	<td class="rounded-foot-right">&nbsp;</td>
					        </tr>
					    </tfoot>
					    <tbody id="inventory">
					    </tbody>
					</table>
				</div>	
				<!-- dialog end -->				
		      	
		      
		        
		        <form action="accountAction!addAccountAction" id="addForm" name="addForm" method="post">
				<table id="rounded-corner" summary="2007 Major IT Companies' Profit">
				    <thead>
				    	<tr>
				        	<th scope="col" class="rounded-company"></th>
				            <th scope="col" class="rounded" ></th>
				            <th scope="col" class="rounded" width="20%" align="right">添加账户</th>
				            <th scope="col" class="rounded"></th>
				            <th scope="col" class="rounded"></th>
				            <th scope="col" class="rounded-q4" width="5%"></th>
				        </tr>
				    </thead>
			        <tfoot>
			    		<tr>
			    			<td  class="rounded-foot-left"></td>
				        	<td></td>
				        	<td colspan="2" style="text-align: left;">
				        	</td>
				        	<td></td>
				        	<td class="rounded-foot-right">&nbsp;</td>
				        </tr>
				    </tfoot>
				    <tbody>
				    	<tr>
				    		<td colspan="6"></td>
				    	</tr>
				    	<tr>
				            <td align="right">名称：</td>
			            	<td align="left"><input type="text" name="account.name" id="name"  size="24"  /></td>
				            <td align="right">单次限额：</td>
				            <td align="left">
				            	<input type="text" name="account.singleExpense" id="singleExpense" size="24"/>
				            </td>
				             <td colspan="2"></td>
				        </tr>   
				        <tr>
			        		<td align="right">选择客户：</td>
				            <td align="left"><input type="text"  name="customer" id="customer"  size="24" onclick="chooseCustomer();"/></td>
				            <td align="right">卡号：</td>
				            <td align="left"><input type="text" name="inventoryNo" id="cardNo"  size="24" onclick="chooseCard();"/></td>
				      		 <td colspan="2"></td>
				        </tr>
				        <tr>
				            <td align="right">信用额度：</td>
				            <td align="left"><input type="text" name="account.creditAmount" id="creditAmount" value="" size="24" maxlength="30" /></td>
				            <td align="right">卡类型：</td>
				            <td align="left">
				            	<s:select list="#application.dics.DIC_CARD_USE_TYPE" listKey="value" listValue="name"  name="cardType" headerKey="-1" headerValue=" -- 请选择 -- "  id="cardType" theme="simple" cssStyle="font-size:12px;"></s:select>
				            </td>
				             <td colspan="2"></td>
				        </tr> 
				        <tr>
			        	   <td align="right">余额不足提醒：</td>
				           <td align="left">
				           		<s:select list="#application.dics.DIC_BALANCE_WARN" listKey="value" listValue="name"  name="account.balanceWarn" id="balanceWarn" headerKey="-1" headerValue=" -- 请选择 -- " theme="simple" cssStyle="font-size:12px;"></s:select>
				           	</td>
				            <td align="right">积分：</td>
				            <td align="left"><input type="text" name="account.score" id="score" value="" size="24" maxlength="30" /></td>
				       		 <td colspan="2"></td>
				        </tr> 
				        <tr>
				        	<td align="right">描述：</td>
				            <td align="left">
								 <input type="text" name="account.accountDesc" id="accountDesc" value="" size="24" maxlength="30" />
				           	</td>
				      		<td colspan="2"><input type="hidden" name="customerId" id="customerId"/></td>
				      		<td colspan="2"></td>
				        </tr> 
				        <tr> <td colspan="6"><span id="error" class="error"></span></td></tr>
				        <tr>
				        	<td colspan="1"></td>
				            <td>
				            	<a href="javascript:addAccount();" class="bt_blue">
		         					<span class="bt_blue_lft"></span><strong>提交</strong><span class="bt_blue_r"></span>
		        				</a>
				            </td>
				            <td>
				            	<a href="javascript:history.back(-1);" class="bt_blue">
		         					<span class="bt_blue_lft"></span><strong>返回</strong><span class="bt_blue_r"></span>
		        				</a>
				            </td>
				            <td colspan="3"></td>
				        </tr>  
				    </tbody>
				</table>
				</form>
		     
			</div>  <!-- end of right content-->
                    
		</div>  <!--end of center content -->               
    
		<div class="clear"></div>
	
    </div>  <!--end of main content-->
	
    <%@include file="../footer.jsp" %>
</div>	
</body>
</html>